﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PlanB.ShareDove.ConferenceOrganization.BusinessLayer.DataLayerInterface.Entities;
using PlanB.ShareDove.ConferenceOrganization.BusinessLayer;
using System.Net;
using PlanB.ShareDove.ConferenceOrganization.ServiceLayer.ShareDoveConferenceOrganizationServices.ShareDoveConferenceProxyService;

namespace PlanB.ShareDove.ConferenceOrganization.ServiceLayer.ShareDoveConferenceOrganizationServices.Entities
{
   
    /// <summary>
    /// SessionContext class manages retrieval of the session data from the SharePoint server
    /// </summary>
    public class SessionContext
    {
        /// <summary>
        /// Reurns sessions as oData
        /// </summary>
        public IQueryable<ConferenceSessionLite> Sessions
        {
            get
            {
                return getSessions();
            }
        }


        /// <summary>
        /// Gets the session information from the wcf service
        /// </summary>
        /// <returns></returns>
        public IQueryable<ConferenceSessionLite> getSessions()
        {
            try
            {

                //
                //use hard coded user credentials here
                //TODO: replace with windows or forms authentication in the future
                WcfServiceClient client = new WcfServiceClient(); 
                client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("Administrator", "123abc?!", "protest2");

                //get sessions
                ConferenceSessionLite[] sessions = client.GetAgendaForDay(new DateTime(2011, 10, 19));

                //return sessions
                return sessions.AsQueryable();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error in retrieving sessions from the service proxy", ex);
            }
        }


        
    }
}